import { WeaSwitch } from 'comsMobx';
import { toJS } from 'mobx';
import {observer } from 'mobx-react';
import React from 'react';
import { WeaSearchGroup, WeaFormItem, WeaTools,WeaCascader,WeaErrorPage,WeaHelpfulTip } from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

@observer
class CptInventoryPlanNew extends React.Component {

    constructor(props) {
        super(props);
    }

    getFormCondition() {
        const { method,form, formcondition} = this.props;
        const { isFormInit } = form;
        let group = [];
        isFormInit && formcondition.map((c,i) => {
            let items = [];
            c.items.map(fields => {
                let hasunderline = false;
                if(fields.viewAttr == "1" || (fields.conditionType == "BROWSER" && fields.browserConditionParam.viewAttr == "1")) {hasunderline = true}  //只读样式控制

                if(fields.conditionType == "SELECT_LINKAGE"){
                    items.push({
                        com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@yvpef2@${fields.domkey[0]}`}
                            error={form.getError(fields)}
                            label={`${fields.label}`}
                            labelCol={{ span: `${fields.labelcol}` }}
                            wrapperCol={{ span: `${fields.fieldcol}` }} underline={hasunderline?true:false}>
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@ivahsl@${fields.domkey[0]}`} fieldConfig={fields} form={form} />
                            <div style={{marginTop:'5px',display:'flex'}}>
                                <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@sow9yk@${fields.domkey[0]}`}
                                style = {{marginLeft: '20px'}}
                                width =  {280} //如果要自定义宽度，在这里设置
                                placement="topRight"
                                title={"1、"+getLabel(518729, "人力类型字段：将资产根据人力字段拆分多个盘点列表，盘点人为该字段值")+
                                        "<br>2、"+getLabel(518925, "仓库类型字段：将资产根据仓库字段拆分多个盘点列表，盘点人为仓库管理员")+
                                            "<br>3、"+getLabel(518730, "部门或者分部类型字段：将资产根据部门或者分部拆分多个盘点列表，盘点人为所选矩阵中维护的值（矩阵中第一个配置值字段）")+
                                            "<br>4、"+getLabel(518731, "重构盘点计划：将不包含在所有盘点列表中的资产，根据以上规则重新生成盘点列表")}
                                />
                            </div>
                        </WeaFormItem>),
                        colSpan: 1
                    })
                }else{
                    items.push({
                        com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@sotfth@${fields.domkey[0]}`}
                            error={form.getError(fields)}
                            label={`${fields.label}`}
                            labelCol={{ span: `${fields.labelcol}` }}
                            wrapperCol={{ span: `${fields.fieldcol}` }} underline={hasunderline?true:false}>
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@i7juql@${fields.domkey[0]}`} fieldConfig={fields} form={form} />
                        </WeaFormItem>),
                        colSpan: 1
                    })
                }
            });

            group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@p9zjjv@${i}`} needTigger={false} col={1} title={c.title} showGroup={c.defaultshow} items={items} />)
        });
        return group;
    }

    render() {
        return (
            <div>
                {this.getFormCondition()}
            </div>
        )
    }
}

export default WeaTools.tryCatch(React,
    props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@jy0acx`} msg={props.error ? props.error : getLabel(383324,'对不起，该页面异常，请联系管理员' )} />,
    { error: "" }
)(CptInventoryPlanNew);